var t = require("../../../utils/themeSkin/skinBehavior"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        dy_password: "",
        details: {},
        language: "",
        current_page: 1,
        last_page: 1,
        list: [],
        choose_index: 1,
        sort_by: 1,
        sort_type: 0,
        sort: {
            up: 0,
            down: 0
        }
    },
    onLoad: function(t) {
        this.getData({
            page: 1
        });
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    onReachBottom: function() {
        this.getMoreData();
    },
    goods_3: function(t) {
        return t && t.length >= 1 ? t.slice(0, 3) : [];
    },
    link: function(t) {
        wx.setStorageSync("tiktok_detail", t.currentTarget.dataset.item), wx.navigateTo({
            url: "/packageF/cps/tiktok_room/tiktok_room"
        });
    },
    getData: function(t) {
        var s = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.tiktok-cps.api.live.live-list"),
            data: t,
            success: function(e) {
                var o = e.data;
                if (0 == o.result) return a.tips(o.msg);
                if (o.data.live_infos && 0 !== o.data.live_infos.length) if (o.data.live_infos.forEach(function(t, a) {
                    t.products && 0 !== t.products.length && (t.goods = t.products.slice(0, 3));
                }), 1 == t.page) s.setData({
                    list: o.data.live_infos
                }); else if (t.page > 1) {
                    var i = s.data.list.concat(o.data.live_infos);
                    s.setData({
                        list: i
                    });
                }
                s.setData({
                    current_page: o.data.current_page,
                    last_page: o.data.last_page
                });
            }
        });
    },
    onClickHide: function() {
        this.setData({
            show: !1
        });
    },
    code_link: function() {
        var t = this;
        wx.setClipboardData({
            data: this.data.dy_password,
            success: function() {
                a.tips("口令已复制，打开抖音app下单！"), t.setData({
                    show: !1
                });
            },
            fail: function(t) {
                a.tips("复制失败");
            }
        });
    },
    copy_handle: function(t) {
        var s = this, e = t.currentTarget.dataset.item;
        a._postNetWork({
            url: a.getNetAddresss("plugin.tiktok-cps.api.live.tranfer-link"),
            data: {
                openid: e.author_openid
            },
            success: function(t) {
                if (0 == t.data.result) return a.tips(t.data.msg);
                s.setData({
                    details: e,
                    dy_password: t.data.data.dy_password,
                    show: !0
                });
            }
        });
    },
    getMoreData: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var t = Number(this.data.current_page) + 1;
            this.getData({
                page: t,
                sort_type: this.data.sort_type,
                sort_by: this.data.sort_by
            });
        }
    },
    choose: function(t) {
        var a = t.currentTarget.dataset.index;
        this.setData({
            choose_index: a
        }), 1 !== Number(a) ? (0 == this.data.sort.up && 0 == this.data.sort.down ? this.setData({
            "sort.up": 1,
            "sort.down": 0
        }) : 1 == this.data.sort.up && 0 == this.data.sort.down ? this.setData({
            "sort.up": 0,
            "sort.down": 1
        }) : 0 == this.data.sort.up && 1 == this.data.sort.down && this.setData({
            "sort.up": 1,
            "sort.down": 0
        }), 1 == this.data.sort.down && this.setData({
            sort_type: 0
        }), 1 == this.data.sort.up && this.setData({
            sort_type: 1
        })) : 1 == a && this.setData({
            "sort.up": 0,
            "sort.down": 0
        });
        var s = a;
        this.setData({
            sort_by: s
        }), this.getData({
            page: 1,
            sort_type: this.data.sort_type,
            sort_by: s
        });
    }
});